#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QButtonGroup>
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
//    QPushButton* pushbutton = new QPushButton(this);

    QIcon icon(":/1.jpg");

    ui->pushButton_target->setIcon(icon);
    ui->pushButton_target->setIconSize(QSize(50,50));

    //设置快捷键：wsad 常见的英文键盘的移动
    ui->pushButton_up->setShortcut(QKeySequence("w"));
    ui->pushButton_right->setShortcut(QKeySequence("d"));
    ui->pushButton_left->setShortcut(QKeySequence("a"));
    ui->pushButton_down->setShortcut(QKeySequence("s"));

    //设置快捷键：wsad 常见的英文键盘的移动
    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));

    //给鼠标添加连击功能：
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);

    ui->radioButton->setChecked(true);//设置为默认选中
    ui->label->setText("您选择的性别是：男");

    ui->radioButton_3->setEnabled(false);


    QButtonGroup* group1 = new QButtonGroup(this);
    group1->addButton(ui->radioButton_4);
    group1->addButton(ui->radioButton_5);
    group1->addButton(ui->radioButton_6);
    QButtonGroup* group2 = new QButtonGroup(this);
    group2->addButton(ui->radioButton_7);
    group2->addButton(ui->radioButton_8);
    group2->addButton(ui->radioButton_9);

    QButtonGroup *group3 = new QButtonGroup(this);
    group3->addButton(ui->radioButton_10);
    group3->addButton(ui->radioButton_11);
    group3->addButton(ui->radioButton_12);

}

Widget::~Widget()
{
    delete ui;
}




void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() + 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() ,rect.y() - 5,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() - 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x(),rect.y() + 5,rect.width(),rect.height());
}

void Widget::on_radioButton_clicked()
{
    //将label文本设置为 您选择...:男
    ui->label->setText("您选择的性别是：男");
}

void Widget::on_radioButton_2_clicked()
{
    ui->label->setText("您选择的性别是：女");
}

void Widget::on_radioButton_3_clicked()
{
    ui->label->setText("您选择的性别是：其他");
}

void Widget::on_pushButton_submit_clicked()
{
    QString str("今日的任务是：");

    //isChecked判断是否被选中
    if(ui->checkBox->isChecked() ){
        //被选中了
        str += QString("学习");
    }
    if(ui->checkBox_2->isChecked()){
        str += QString("打球");
    }
    if(ui->checkBox_3->isChecked()){

        str += QString("打游戏");
    }
    ui->label_5->setText(str);
}

